(function($){
	$.ajat = function(params){
 
      // use extend to merge our defaults with parameters
      // passed by function caller
      var settings = $.extend({
    	type: "GET",
        url: "",
        spinner:  {}, 
          // use empty object if version 1.3.2-
        dataType: "html",
        data: {},
        cache:    false,
        success:  function(){},
        errorMsg: "Fail to process",
        retry: 0 //maximum retries if 504 error happen
      }, params),
          retries = 0; // setting up retries variable
     // setting up a function that we can call recursively
     // to retry ajax calls 
     function ajaxRequest () {
        $.ajax({
          type: settings.type,
          beforeSend: function() { 
            $(settings.spinner).show();
          },
          url: settings.url,
          dataType: settings.dataType,
          data: settings.data,
          success: settings.success,
          complete: function() {
            $(settings.spinner).hide();
          },
          error: function( xhr, tStatus, err ) {
            if( xhr.status === 401 || xhr.status === 403 ) {
              //redirect action here
            } else if ( xhr.status === 504 && (retries++ < retry) ) {
              //make our recursive request
              ajaxRequest();
            } else {
              $(document).trigger("ajat.error", 
                [{ message: settings.errorMsg }] );
            }
          } // end error handler
        }); // end $.ajax()
      }; // end ajaxRequest() 
       
      // call our ajax request function. notice above
      // that we only define the function. here we make
      // the original call.
      ajaxRequest();
         
    }; // end getViaAjax()
})(jQuery);